<?php

namespace App\Http\Controllers\Seller;

use App\Http\Controllers\Controller;
use App\Services\RefundService;
use Illuminate\Http\Request;

class RefundCate extends Controller
{

    public $refundService;

    public $refundModel;

    public function __construct()
    {
        $this->refundService = new \App\Services\RefundCate();
        $this->refundModel = new \App\Models\RefundCate();
    }


    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        try {
            return $this->refundService->getList();
        } catch (\Exception $e) {
            return $this->format([], '获取失败' . $e->getMessage());
        }
    }

    /**
     * 2021/3/12--15:41
     * @param Request $request
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:store
     * @effect:添加
     */
    public function store(Request $request)
    {
        try {
            return $this->refundService->add();
        } catch (\Exception $e) {
            $this->error([], '添加失败' . $e->getMessage());
        }
    }


    /**
     * 2021/3/12--15:41
     * @param $id
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:show
     * @effect:查看
     */
    public function show($id)
    {
        try {
            return $this->refundService->show($id);
        } catch (\Exception $e) {
            return $this->error([], '获取失败' . $e->getMessage());
        }
    }


    /**
     * 2021/3/12--15:42
     * @param $id
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:edit
     * @effect:修改
     */
    public function edit($id)
    {
        try {
            return $this->refundService->edit($id);
        } catch (\Exception $e) {
            return $this->error('修改失败' . $e->getMessage());
        }
    }

    /**
     * Update the specified resource in storage.
     *
     * @param \Illuminate\Http\Request $request
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        try {
            return $this->refundService->edit($id);
        } catch (\Exception $e) {
            return $this->error('修改失败' . $e->getMessage());
        }
    }

    /**
     * 2021/3/12--15:42
     * @param $ids
     * @return array
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:destroy
     * @effect:刪除
     */
    public function destroy($ids)
    {
        try {
            return $this->refundService->del($ids);
        } catch (\Exception $e) {
            return $this->error('删除失败');
        }
    }


    /**
     * 2021/3/12--15:30
     * @author:董宗澳
     * @email:2453611300
     * @wechat:DZA74941
     * @QQ:2453611300
     * @web:www.quzha.net
     * @method:edit_refund_cate_show
     * @effect:修改分类显示状态
     */
    public function edit_refund_cate_show(Request $request)
    {
        $id = $request->post('id');
        $data = $this->refundModel->where('id', $id)->first();
        $refundStatus = $data['is_show'] == 1 ? 0 : 1;
        $data->is_show = $refundStatus;
        return $data->save() ? $this->success([], '修改成功!') : $this->error([], '修改失败!');
    }
}
